﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace project4
{
    public partial class Form1 : Form
    {
        public static Form1 form1;

        private List<User> users;
        public Form1(Table table)
        {
            
            this.users = table.Users;
            InitializeComponent();
            form1 = this;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.Columns.Add("ID", "ID");
            dataGridView1.Columns.Add("Account", "Account");
            dataGridView1.Columns.Add("Password", "Password");
            dataGridView1.Columns.Add("UserType", "UserType");

            dataGridView1_Load(users);
        }

        private void dataGridView1_Load(List<User> musers)
        {
            for (int i = 0; i < musers.Count; i++)
            {
                int index = dataGridView1.Rows.Add();

                dataGridView1.Rows[index].Cells[0].Value = musers[i].ID1;
                dataGridView1.Rows[index].Cells[1].Value = musers[i].Account1;
                dataGridView1.Rows[index].Cells[2].Value = musers[i].Password1;
                dataGridView1.Rows[index].Cells[3].Value = musers[i].UserType1;
            }
        }

        public void dataGrodView1_Add(User user)
        {
            int index = dataGridView1.Rows.Add();

            dataGridView1.Rows[index].Cells[0].Value = user.ID1;
            dataGridView1.Rows[index].Cells[1].Value = user.Account1;
            dataGridView1.Rows[index].Cells[2].Value = user.Password1;
            dataGridView1.Rows[index].Cells[3].Value = user.UserType1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Table table = new Table();

            //创建观察者对象
            Updated dataUpdated = new DataUpdate();

            //注册观察者
            table.AddObserver(dataUpdated);

            //添加的数据
            User user = new User(4, "ddd", "ddd", 1);
            //进行添加
            table.Add(user);    
        }
    }
}
